package com.htj.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {
    private Integer code;//状态码,200表示成功
    private String msg;//消息
    private T data;//数据
    private Result(){}

    public static <T> Result<T> build(T data){
        Result result=new Result();
        if(result!=null)
            result.setData(data);
        return result;
    }
    public static <T> Result<T> build(T data,ResultCodeEnum resultCodeEnum){
        Result result=build(data);
        result.setCode(resultCodeEnum.getCode());
        result.setMsg(resultCodeEnum.getMsg());
        return result;
    }
    public static <T>  Result<T> build(Integer code,String msg){
        Result result=build(null);
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }


    //对外暴露的方法
    public static <T>  Result<T> succ(T data){
        return Result.build(data,ResultCodeEnum.SUCCESS);
    }
    public static <T>  Result<T> succ(){
        return succ(null);
    }
    public static <T>  Result<T> fail(T data){
        return Result.build(data,ResultCodeEnum.FAIL);
    }
    public static <T>  Result<T> fail(){
        return fail(null);
    }


}
